from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-05-06 14:08:44.460572
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 06, May, 2021
Time: 14:08:49
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0316
Nobs: 283.000 HQIC: -48.7260
Log likelihood: 3436.47 FPE: 4.33295e-22
AIC: -49.1909 Det(Omega_mle): 3.16996e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.402758 0.117712 3.422 0.001
L1.Burgenland 0.071240 0.059273 1.202 0.229
L1.Kärnten -0.224435 0.052723 -4.257 0.000
L1.Niederösterreich 0.108648 0.126905 0.856 0.392
L1.Oberösterreich 0.217153 0.123096 1.764 0.078
L1.Salzburg 0.276235 0.067728 4.079 0.000
L1.Steiermark 0.107785 0.086378 1.248 0.212
L1.Tirol 0.120593 0.059941 2.012 0.044
L1.Vorarlberg -0.031528 0.054959 -0.574 0.566
L1.Wien -0.040159 0.110629 -0.363 0.717
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.430702 0.135768 3.172 0.002
L1.Burgenland 0.003280 0.068365 0.048 0.962
L1.Kärnten 0.329133 0.060810 5.413 0.000
L1.Niederösterreich 0.121149 0.146371 0.828 0.408
L1.Oberösterreich -0.070330 0.141978 -0.495 0.620
L1.Salzburg 0.227507 0.078117 2.912 0.004
L1.Steiermark 0.088697 0.099628 0.890 0.373
L1.Tirol 0.136074 0.069135 1.968 0.049
L1.Vorarlberg 0.151951 0.063389 2.397 0.017
L1.Wien -0.409023 0.127599 -3.206 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.250915 0.059879 4.190 0.000
L1.Burgenland 0.105255 0.030151 3.491 0.000
L1.Kärnten -0.013723 0.026819 -0.512 0.609
L1.Niederösterreich 0.097791 0.064555 1.515 0.130
L1.Oberösterreich 0.279696 0.062618 4.467 0.000
L1.Salzburg 0.022465 0.034452 0.652 0.514
L1.Steiermark -0.003541 0.043940 -0.081 0.936
L1.Tirol 0.067927 0.030491 2.228 0.026
L1.Vorarlberg 0.076656 0.027957 2.742 0.006
L1.Wien 0.118213 0.056276 2.101 0.036
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208747 0.057091 3.656 0.000
L1.Burgenland 0.028251 0.028748 0.983 0.326
L1.Kärnten 0.009586 0.025571 0.375 0.708
L1.Niederösterreich 0.056952 0.061550 0.925 0.355
L1.Oberösterreich 0.393548 0.059703 6.592 0.000
L1.Salzburg 0.081030 0.032849 2.467 0.014
L1.Steiermark 0.131485 0.041894 3.139 0.002
L1.Tirol 0.050685 0.029072 1.743 0.081
L1.Vorarlberg 0.081647 0.026655 3.063 0.002
L1.Wien -0.042651 0.053656 -0.795 0.427
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.442377 0.112223 3.942 0.000
L1.Burgenland 0.103321 0.056509 1.828 0.067
L1.Kärnten 0.009904 0.050264 0.197 0.844
L1.Niederösterreich 0.033567 0.120987 0.277 0.781
L1.Oberösterreich 0.113146 0.117356 0.964 0.335
L1.Salzburg 0.062183 0.064569 0.963 0.336
L1.Steiermark 0.063095 0.082350 0.766 0.444
L1.Tirol 0.201952 0.057145 3.534 0.000
L1.Vorarlberg 0.038016 0.052396 0.726 0.468
L1.Wien -0.062473 0.105470 -0.592 0.554
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.211673 0.088091 2.403 0.016
L1.Burgenland -0.011425 0.044357 -0.258 0.797
L1.Kärnten -0.006457 0.039455 -0.164 0.870
L1.Niederösterreich -0.014734 0.094970 -0.155 0.877
L1.Oberösterreich 0.416512 0.092120 4.521 0.000
L1.Salzburg 0.012443 0.050685 0.246 0.806
L1.Steiermark -0.027621 0.064642 -0.427 0.669
L1.Tirol 0.161909 0.044857 3.609 0.000
L1.Vorarlberg 0.058403 0.041129 1.420 0.156
L1.Wien 0.205057 0.082790 2.477 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195901 0.107508 1.822 0.068
L1.Burgenland 0.022984 0.054135 0.425 0.671
L1.Kärnten -0.071069 0.048152 -1.476 0.140
L1.Niederösterreich -0.038919 0.115904 -0.336 0.737
L1.Oberösterreich 0.006920 0.112426 0.062 0.951
L1.Salzburg 0.090899 0.061857 1.470 0.142
L1.Steiermark 0.316329 0.078890 4.010 0.000
L1.Tirol 0.461498 0.054745 8.430 0.000
L1.Vorarlberg 0.148253 0.050194 2.954 0.003
L1.Wien -0.130762 0.101039 -1.294 0.196
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203099 0.127760 1.590 0.112
L1.Burgenland 0.040540 0.064332 0.630 0.529
L1.Kärnten -0.074478 0.057223 -1.302 0.193
L1.Niederösterreich 0.117956 0.137738 0.856 0.392
L1.Oberösterreich 0.012439 0.133604 0.093 0.926
L1.Salzburg 0.194199 0.073509 2.642 0.008
L1.Steiermark 0.130161 0.093752 1.388 0.165
L1.Tirol 0.055481 0.065057 0.853 0.394
L1.Vorarlberg 0.106948 0.059650 1.793 0.073
L1.Wien 0.221499 0.120073 1.845 0.065
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512937 0.070947 7.230 0.000
L1.Burgenland -0.013727 0.035725 -0.384 0.701
L1.Kärnten -0.016647 0.031777 -0.524 0.600
L1.Niederösterreich 0.108690 0.076488 1.421 0.155
L1.Oberösterreich 0.304347 0.074192 4.102 0.000
L1.Salzburg 0.019995 0.040821 0.490 0.624
L1.Steiermark -0.046954 0.052062 -0.902 0.367
L1.Tirol 0.079506 0.036127 2.201 0.028
L1.Vorarlberg 0.103332 0.033124 3.120 0.002
L1.Wien -0.048452 0.066678 -0.727 0.467
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.161108 0.094421 0.168844 0.221784 0.078097 0.089580 0.001494 0.163427
Kärnten 0.161108 1.000000 0.056417 0.212242 0.186417 -0.065999 0.177954 0.021635 0.307268
Niederösterreich 0.094421 0.056417 1.000000 0.244557 0.099881 0.317766 0.154709 0.025888 0.321141
Oberösterreich 0.168844 0.212242 0.244557 1.000000 0.302079 0.260626 0.104565 0.061703 0.142310
Salzburg 0.221784 0.186417 0.099881 0.302079 1.000000 0.149904 0.072570 0.091086 0.029427
Steiermark 0.078097 -0.065999 0.317766 0.260626 0.149904 1.000000 0.095003 0.100352 -0.099370
Tirol 0.089580 0.177954 0.154709 0.104565 0.072570 0.095003 1.000000 0.152769 0.162393
Vorarlberg 0.001494 0.021635 0.025888 0.061703 0.091086 0.100352 0.152769 1.000000 -0.008913
Wien 0.163427 0.307268 0.321141 0.142310 0.029427 -0.099370 0.162393 -0.008913 1.000000